class Storage {
  // 设置 localStorage
  static setLocal(key, value) {
    if (typeof value === 'object') {
      value = JSON.stringify(value)
    }
    localStorage.setItem(key, value)
  }

  // 获取 localStorage
  static getLocal(key) {
    const value = localStorage.getItem(key)
    try {
      return JSON.parse(value)
    } catch (e) {
      return value
    }
  }

  // 移除 localStorage
  static removeLocal(key) {
    localStorage.removeItem(key)
  }

  // 清空 localStorage
  static clearLocal() {
    localStorage.clear()
  }

  // 设置 sessionStorage
  static setSession(key, value) {
    if (typeof value === 'object') {
      value = JSON.stringify(value)
    }
    sessionStorage.setItem(key, value)
  }

  // 获取 sessionStorage
  static getSession(key) {
    const value = sessionStorage.getItem(key)
    try {
      return JSON.parse(value)
    } catch (e) {
      return value
    }
  }

  // 移除 sessionStorage
  static removeSession(key) {
    sessionStorage.removeItem(key)
  }

  // 清空 sessionStorage
  static clearSession() {
    sessionStorage.clear()
  }
}

export default Storage 